package com.srwl.mytx;

import com.srwl.mytx.converter.EncryptInterceptor;
import com.srwl.mytx.converter.MyConverterFactory;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

/**
 * Created by dahai2070 on 2018/2/9 0009.
 */

public class RetrofitManager {
    //private static final String BASEURL = "http:192.168.0.105:8001/";
    //  private static final String BASEURL = "http:47.93.203.229/";
    // private static final String BASEURL = "http://217m9531g7.iask.in:47955";
    private Retrofit retrofit;
    private static RetrofitManager retrofitManager;

    public static synchronized RetrofitManager getInstance() {
        if (retrofitManager == null) {
            retrofitManager = new RetrofitManager();
        }
        return retrofitManager;
    }

    private RetrofitManager() {
        retrofit = new Retrofit
                .Builder()
                .baseUrl(BuildConfig.SERVER_HOST)
                // .addConverterFactory(FastJsonConverterFactory.create())
                .addConverterFactory(MyConverterFactory.create())
                // .addConverterFactory(GsonConverterFactory.create())
                .client(new OkHttpClient.Builder().addInterceptor(new EncryptInterceptor()).build())
                .build();
    }


    /**
     * 返回实现类
     *
     * @param reqServer 传入接口类
     * @param <T>
     * @return
     */
    public <T> T createRequest(Class<T> reqServer) {
        return retrofit.create(reqServer);
    }
}
